package com.blue.controller;


import VO.VOLine;
import com.blue.VO.Result;
import com.blue.entity.Line;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import com.blue.service.LineService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author blue
 * @since 2024-11-25
 */
@RestController
@RequestMapping("/line")
public class LineController {
    @Autowired
    LineService lineService;


    @RequestMapping("/{name}")
    public Result showLine(@PathVariable("name") String name){
        Line lineByName = lineService.findLineByName(name);
        VOLine voLine = new VOLine();
        if(lineByName == null){
            return Result.fail(404,"根据线号名无搜索结果");
        }
        BeanUtils.copyProperties(lineByName,voLine);
        voLine.setStations(lineService.findStations(lineByName));
        return Result.success(voLine);
    }
}

